local skel = fk.CreateSkill{
  name = "tea__shiyin",
  tags = { Skill.Compulsory, Skill.AttachedKingdom },
  attached_kingdom = { "shu" },
}
--local U = require "packages/utility/utility"
Fk:loadTranslationTable{
  ["tea__shiyin"] = "仕荫",
  [":tea__shiyin"] = "蜀势力技，锁定技，每回合结束时，你选择并获得一张本回合进入弃牌堆的牌（此牌点数须大于你此前以此法获得过的牌）。若你未以此法获得牌，你将势力改为晋。",
  ["@tea__shiyin"] = "仕荫",
  ["#tea__shiyin-card"] = "仕荫：选择一张牌获得",
}
---@type TrigSkelSpec<TurnFunc>
local shiyin = {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(skel.name) then
      local room = player.room
      local turn_id = (room.logic:getCurrentEvent():findParent(GameEvent.Turn, true) or {}).id
      if turn_id then
        local centre_area = {}
        room.logic:getEventsByRule(GameEvent.MoveCards, 1, function (e)
          for _, move in ipairs(e.data) do
            if move.toArea == Card.DiscardPile then
              for _, info in ipairs(move.moveInfo) do
                if table.contains(room.discard_pile, info.cardId) then
                  table.insertIfNeed(centre_area, info.cardId)
                end
              end
            end
          end
          return false
        end, turn_id)
        if #centre_area > 0 then
          event:setCostData(self, { ids = centre_area })
          return true
        end
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local ids = event:getCostData(self).ids ---@type integer[]
    local mark = player:getMark("@tea__shiyin")
    local avaIds = table.filter(ids, function (id)
      return Fk:getCardById(id).number > mark
    end)
    local cid = room:askToChooseCardsAndChoice(player, {
      cards = avaIds,
      all_cards = ids,
      skill_name = skel.name,
      prompt = "#tea__shiyin-card",
      choices = { "OK" },
      min_num = #avaIds > 0 and 1 or 0
    })
    if #cid == 1 then
      room:setPlayerMark(player, "@tea__shiyin", Fk:getCardById(cid[1]).number)
      room:obtainCard(player, cid, true, fk.ReasonJustMove, player, skel.name)
    elseif #cid == 0 then
      room:changeKingdom(player, "jin", true)
    end
  end
}
skel:addEffect(fk.TurnEnd, shiyin)
-- Fk.generals["mouxusheng"]:addSkill(skel.name)
return skel